import { getMenuByRouter } from '@/libs/utils'
import cache from '@/libs/cache'
import { ACCESS_TOKEN, LOGIN_USER_INFO } from './mutation-types'

const getters = {
    menuList: state => getMenuByRouter(state.permission.asyncRoutes),
    asyncRoutes: state => state.permission.asyncRoutes,
    errorCount: state => state.app.errorList.length,
    userInfo: (state) => {
        let info = state.user.userInfo;
        if (info && Object.keys(info).length < 1) {
            info = cache.get(LOGIN_USER_INFO) || {}
        }
        return info;
    },
    token: state => {
        let token = state.user.token;
        if (token) return token;
        return cache.get(ACCESS_TOKEN)
    },
}

export default getters